home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 008 / src / hack.u_init.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  7KB  |  309 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
  2.  
  3. #include "hack.h"
  4. #include <stdio.h>
  5. #ifndef AMIGA
  6. #include <signal.h>
  7. #endif
  8. #define   Strcat   (void) strcat
  9. #define   UNDEF_TYP   0
  10. #define   UNDEF_SPE   (-1)
  11. extern struct obj *addinv();
  12. extern char plname[];
  13.  
  14. char pl_character[PL_CSIZ];
  15.  
  16. struct trobj {
  17.    uchar trotyp;
  18.    schar trspe;
  19.    char trolet;
  20.    Bitfield(trquan,6);
  21.    Bitfield(trknown,1);
  22. };
  23.  
  24. #ifdef WIZARD
  25. struct trobj Extra_objs[] = {
  26.    { 0, 0, 0, 0, 0 },
  27.    { 0, 0, 0, 0, 0 }
  28. };
  29. #endif WIZARD
  30.  
  31. struct trobj Cave_man[] = {
  32.    { MACE, 1, WEAPON_SYM, 1, 1 },
  33.    { BOW, 1, WEAPON_SYM, 1, 1 },
  34.    { ARROW, 0, WEAPON_SYM, 25, 1 },   /* quan is variable */
  35.    { LEATHER_ARMOR, 2, ARMOR_SYM, 1, 1 },
  36.    { 0, 0, 0, 0, 0}
  37. };
  38.  
  39. struct trobj Fighter[] = {
  40.    { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
  41.    { RING_MAIL, 3, ARMOR_SYM, 1, 1 },
  42.    { 0, 0, 0, 0, 0 }
  43. };
  44.  
  45. struct trobj Knight[] = {
  46.    { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
  47.    { SPEAR, 2, WEAPON_SYM, 1, 1 },
  48.    { RING_MAIL, 4, ARMOR_SYM, 1, 1 },
  49.    { HELMET, 1, ARMOR_SYM, 1, 1 },
  50.    { SHIELD, 1, ARMOR_SYM, 1, 1 },
  51.    { PAIR_OF_GLOVES, 1, ARMOR_SYM, 1, 1 },
  52.    { 0, 0, 0, 0, 0 }
  53. };
  54.  
  55. struct trobj Speleologist[] = {
  56.    { STUDDED_LEATHER_ARMOR, 3, ARMOR_SYM, 1, 1 },
  57.    { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
  58.    { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
  59.    { ICE_BOX, 0, TOOL_SYM, 1, 0 },
  60.    { 0, 0, 0, 0, 0}
  61. };
  62.  
  63. struct trobj Tourist[] = {
  64.    { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
  65.    { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
  66.    { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
  67.    { DART, 2, WEAPON_SYM, 25, 1 },   /* quan is variable */
  68.    { 0, 0, 0, 0, 0 }
  69. };
  70.  
  71. struct trobj Wizard[] = {
  72.    { ELVEN_CLOAK, 1, ARMOR_SYM, 1, 1 },
  73.    { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
  74.    { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
  75.    { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
  76.    { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
  77.    { 0, 0, 0, 0, 0 }
  78. };
  79.  
  80. #ifdef NEWS
  81. int u_in_infl;
  82.  
  83. u_in_intrup()
  84. {
  85.    u_in_infl++;
  86. #ifndef AMIGA
  87.    (void) signal(SIGINT, u_in_intrup);
  88. #endif
  89. }
  90. #endif NEWS
  91.  
  92. u_init(){
  93. register int c,pc,i;
  94. #ifdef NEWS
  95.    /* It is not unlikely that we get an interrupt here
  96.       intended to kill the news; unfortunately this would
  97.       also kill (part of) the following question */
  98. #ifndef AMIGA
  99. int (*prevsig)() = signal(SIGINT, u_in_intrup);
  100. #endif
  101. #endif NEWS
  102. register char *cp;
  103. char buf[256];
  104.    if(pc = pl_character[0]) goto got_suffix;
  105.    buf[0] = 0;
  106.    Strcat(buf, "\nTell me what kind of character you are:\n");
  107.    Strcat(buf, "Are you a Tourist, a Speleologist, a Fighter,\n");
  108.    Strcat(buf, "        a Knight, a Cave-man or a Wizard? [TSFKCW] ");
  109. intrup:
  110.    for(cp = buf; *cp; cp++){
  111. #ifdef NEWS
  112.       if(u_in_infl){
  113.          u_in_infl = 0;
  114.          goto intrup;
  115.       }
  116. #endif NEWS
  117.       (void) myputchar(*cp);
  118.    }
  119. loop:
  120.    (void) myfflush(stdout);
  121.    pc = 0;
  122.    while((c = inchar()) != '\n') {
  123. #ifndef AMIGA
  124.       if(c == EOF) {
  125. #ifdef NEWS
  126.          if(u_in_infl) goto intrup;   /* %% */
  127. #endif NEWS
  128.          settty("\nEnd of input?\n");
  129.          hackexit(0);
  130.          }
  131.       else
  132. #endif !AMIGA
  133.          if(pc && c==8)  /* backspace over it? */
  134.          {
  135.          myputchar(c);
  136.          pc = 0;
  137.          }
  138.       else if (!pc)
  139.          {
  140.          pc = c;
  141.          myputchar(c);
  142.          }
  143.    }
  144.    if(!pc || !strchr("TSFKCWtsfkcw", pc)){
  145.       myprintf("\nAnswer with T,S,F,K,C or W. What are you? ");
  146.       goto loop;
  147.    }
  148. got_suffix:
  149.    if('a' <= pc && pc <= 'z') pc += 'A'-'a';
  150.  
  151. #ifndef AMIGA
  152. #ifdef NEWS
  153.    (void) signal(SIGINT,prevsig);
  154. #endif NEWS
  155. #endif AMIGA
  156.  
  157.    u.usym = '@';
  158.    u.ulevel = 1;
  159.    init_uhunger();
  160.    u.uhpmax = u.uhp = 12;
  161.    u.ustrmax = u.ustr = !rn2(20) ? 14 + rn2(7) : 16;
  162. #ifdef QUEST
  163.    u.uhorizon = 6;
  164. #endif QUEST
  165.    switch(pc) {
  166.    case 'C':
  167.       setpl_char("Cave-man");
  168.       Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
  169.       u.uhp = u.uhpmax = 16;
  170.       u.ustr = u.ustrmax = 18;
  171.       ini_inv(Cave_man);
  172.       break;
  173.    case 'T':
  174.       setpl_char("Tourist");
  175.       Tourist[3].trquan = 20 + rnd(20);
  176.       u.ugold = u.ugold0 = rnd(1000);
  177.       u.uhp = u.uhpmax = 10;
  178.       u.ustr = u.ustrmax = 8;
  179.       ini_inv(Tourist);
  180.       break;
  181.    case 'W':
  182.       setpl_char("Wizard");
  183.       for(i=1; i<=4; i++) if(!rn2(5))
  184.          Wizard[i].trquan += rn2(3) - 1;
  185.       u.uhp = u.uhpmax = 15;
  186.       u.ustr = u.ustrmax = 16;
  187.       ini_inv(Wizard);
  188.       break;
  189.    case 'S':
  190.       setpl_char("Speleologist");
  191.       Fast = INTRINSIC;
  192.       Stealth = INTRINSIC;
  193.       u.uhp = u.uhpmax = 12;
  194.       u.ustr = u.ustrmax = 10;
  195.       ini_inv(Speleologist);
  196.       break;
  197.    case 'K':
  198.       setpl_char("Knight");
  199.       u.uhp = u.uhpmax = 12;
  200.       u.ustr = u.ustrmax = 10;
  201.       ini_inv(Knight);
  202.       break;
  203.    case 'F':
  204.       setpl_char("Fighter");
  205.       u.uhp = u.uhpmax = 14;
  206.       u.ustr = u.ustrmax = 17;
  207.       ini_inv(Fighter);
  208.    }
  209.    find_ac();
  210.    /* make sure he can carry all he has - especially for T's */
  211.    while(inv_weight() > 0 && u.ustr < 118)
  212.       u.ustr++, u.ustrmax++;
  213. #ifdef WIZARD
  214.    if(wizard) wiz_inv();
  215. #endif WIZARD
  216. }
  217.  
  218. ini_inv(trop) register struct trobj *trop; {
  219. register struct obj *obj;
  220. extern struct obj *mkobj();
  221.    while(trop->trolet) {
  222.       obj = mkobj(trop->trolet);
  223.       obj->known = trop->trknown;
  224.       obj->cursed = 0;
  225.       if(obj->olet == WEAPON_SYM){
  226.          obj->quan = trop->trquan;
  227.          trop->trquan = 1;
  228.       }
  229.       if(trop->trspe != UNDEF_SPE)
  230.          obj->spe = trop->trspe;
  231.       if(trop->trotyp != UNDEF_TYP)
  232.          obj->otyp = trop->trotyp;
  233.       obj->owt = weight(obj);   /* defined after setting otyp+quan */
  234.       obj = addinv(obj);
  235.       if(obj->olet == ARMOR_SYM){
  236.          switch(obj->otyp){
  237.          case SHIELD:
  238.             if(!uarms) setworn(obj, W_ARMS);
  239.             break;
  240.          case HELMET:
  241.             if(!uarmh) setworn(obj, W_ARMH);
  242.             break;
  243.          case PAIR_OF_GLOVES:
  244.             if(!uarmg) setworn(obj, W_ARMG);
  245.             break;
  246.          case ELVEN_CLOAK:
  247.             if(!uarm2)
  248.                setworn(obj, W_ARM);
  249.             break;
  250.          default:
  251.             if(!uarm) setworn(obj, W_ARM);
  252.          }
  253.       }
  254.       if(obj->olet == WEAPON_SYM)
  255.          if(!uwep) setuwep(obj);
  256.       if(--trop->trquan) continue;   /* make a similar object */
  257.       trop++;
  258.    }
  259. }
  260.  
  261. #ifdef WIZARD
  262. wiz_inv(){
  263. register struct trobj *trop = &Extra_objs[0];
  264. extern char *getenv();
  265. register char *ep = getenv("INVENT");
  266. register int type;
  267.    while(ep && *ep) {
  268.       type = atoi(ep);
  269.       ep = strchr(ep, ',');
  270.       if(ep) while(*ep == ',' || *ep == ' ') ep++;
  271.       if(type <= 0 || type > NROFOBJECTS) continue;
  272.       trop->trotyp = type;
  273.       trop->trolet = objects[type].oc_olet;
  274.       trop->trspe = 4;
  275.       trop->trknown = 1;
  276.       trop->trquan = 1;
  277.       ini_inv(trop);
  278.    }
  279.    /* give him a wand of wishing by default */
  280.    trop->trotyp = WAN_WISHING;
  281.    trop->trolet = WAND_SYM;
  282.    trop->trspe = 20;
  283.    trop->trknown = 1;
  284.    trop->trquan = 1;
  285.    ini_inv(trop);
  286. }
  287. #endif WIZARD
  288.  
  289. setpl_char(plc) char *plc; {
  290.    (void) strncpy(pl_character, plc, PL_CSIZ-1);
  291.    pl_character[PL_CSIZ-1] = 0;
  292. }
  293.  
  294. plnamesuffix() {
  295. register char *p;
  296.    if(p = strrchr(plname, '-')) {
  297.       *p = 0;
  298.       if(!plname[0]) {
  299.          askname();
  300.          plnamesuffix();
  301.       }
  302.       if(strchr("TSFKCWtsfkcw", p[1])) {
  303.          pl_character[0] = p[1];
  304.          pl_character[1] = 0;
  305.       }
  306.    }
  307. }
  308.  
  309.